package com.gem.shop.service.impl;

import com.gem.shop.dao.CommodityDao;
import com.gem.shop.entity.Commodity;
import com.gem.shop.service.CommodityService;
import com.gem.shop.util.BeanFactory;
import com.gem.shop.util.PageBean;

import java.util.List;

/**
 * @author zhang
 * @date 2020/9/17 19:27
 */
public class CommodityServiceImpl implements CommodityService {
    CommodityDao commodityDao = (CommodityDao) BeanFactory.getBean("commodityDao");

    @Override
    public PageBean<Commodity> findCommoditysByPagesAndName(int pageNow, int pageSize, String name) {
        List<Commodity> commodities = commodityDao.selectCommoditysByPagesAndName(pageNow,pageSize,name);
        Long count = commodityDao.selectCommoditysByPagesAndNameCount(name);
        PageBean<Commodity> pageBean = new PageBean<>(commodities,pageNow,pageSize,count);
        return pageBean;
    }

    @Override
    public PageBean<Commodity> findCommoditysByPagesAndType(int pageNow,int pageSize,String type) {
        List<Commodity> commodities = commodityDao.selectCommoditysByPagesAndType(pageNow,pageSize,type);
        long count = commodityDao.selectCommoditysByTypeCount(type);
        PageBean<Commodity> pageBean = new PageBean<>(commodities,pageNow,pageSize,count);
        return pageBean;
    }

    @Override
    public List<String> findAllType() {
        return commodityDao.selectAllType();
    }

    @Override
    public Commodity findCommodityById(int id) {
        return commodityDao.selectCommodityById(id);
    }

    @Override
    public List<Commodity> findCommoditiesByNameAndType(String name, String type) {
        return commodityDao.selectCommodityByNameAndType(name,type);
    }

}
